package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.PspWarnResultRptDao;
import com.fdb.efp.nls.service.domain.PspWarnResultRpt;
import com.fdb.efp.nls.service.facade.PspWarnResultRptService;
import com.fdb.efp.nls.service.vo.PspWarnResultRptVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 贷后检查报告预警结果表				<p>
 * @author chenqm1
 * @date 2018-05-07
 */
@Service("pspWarnResultRptService")
public class PspWarnResultRptServiceImpl implements PspWarnResultRptService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PspWarnResultRptServiceImpl.class);

	@Autowired
	private PspWarnResultRptDao pspWarnResultRptDao;
	
	/**
	 * 新增操作
	 */
	public int insertPspWarnResultRpt(PspWarnResultRptVO inPspWarnResultRptVo) {
		logger.debug("当前新增数据为:"+ inPspWarnResultRptVo.toString());
		int num = 0;
		try {
			PspWarnResultRpt pspWarnResultRpt = new PspWarnResultRpt();
			beanCopy(inPspWarnResultRptVo, pspWarnResultRpt);
			num = pspWarnResultRptDao.insertPspWarnResultRpt(pspWarnResultRpt);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PspWarnResultRptVO inPspWarnResultRptVo) {
		logger.debug("当前删除数据条件为:"+ inPspWarnResultRptVo);
		int num = 0;
		try {
			PspWarnResultRpt pspWarnResultRpt = new PspWarnResultRpt();
			beanCopy(inPspWarnResultRptVo, pspWarnResultRpt);
			num = pspWarnResultRptDao.deleteByPk(pspWarnResultRpt);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPspWarnResultRptVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PspWarnResultRptVO inPspWarnResultRptVo) {
		logger.debug("当前修改数据为:"+ inPspWarnResultRptVo.toString());
		int num = 0;
		try {
			PspWarnResultRpt pspWarnResultRpt = new PspWarnResultRpt();
			beanCopy(inPspWarnResultRptVo, pspWarnResultRpt);
			num = pspWarnResultRptDao.updateByPk(pspWarnResultRpt);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPspWarnResultRptVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PspWarnResultRptVO queryByPk(PspWarnResultRptVO inPspWarnResultRptVo) {
		
		logger.debug("当前查询参数信息为:"+ inPspWarnResultRptVo);
		try {
			PspWarnResultRpt queryPspWarnResultRpt = new PspWarnResultRpt();
			beanCopy(inPspWarnResultRptVo, queryPspWarnResultRpt);
			PspWarnResultRpt queryRslPspWarnResultRpt = pspWarnResultRptDao.queryByPk(queryPspWarnResultRpt);
			if (Objects.nonNull(queryRslPspWarnResultRpt)) {
				PspWarnResultRptVO outPspWarnResultRptVo = beanCopy(queryRslPspWarnResultRpt, new PspWarnResultRptVO());
				logger.debug("当前查询结果为:"+ outPspWarnResultRptVo.toString());
				return outPspWarnResultRptVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PspWarnResultRptVO> queryAllOwner(PspWarnResultRptVO pspWarnResultRptVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PspWarnResultRptVO> list = null;
		try {
			List<PspWarnResultRpt> pspWarnResultRpts = pspWarnResultRptDao.queryAllOwnerByPage(pspWarnResultRptVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pspWarnResultRpts.size());
			pageSet(pspWarnResultRpts, pspWarnResultRptVo);
			list = (List<PspWarnResultRptVO>) beansCopy(pspWarnResultRpts, PspWarnResultRptVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PspWarnResultRptVO> queryAllCurrOrg(PspWarnResultRptVO pspWarnResultRptVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PspWarnResultRpt> pspWarnResultRpts = pspWarnResultRptDao.queryAllCurrOrgByPage(pspWarnResultRptVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pspWarnResultRpts.size());
		List<PspWarnResultRptVO> list = null;
		try {
			pageSet(pspWarnResultRpts, pspWarnResultRptVo);
			list = (List<PspWarnResultRptVO>) beansCopy(pspWarnResultRpts, PspWarnResultRptVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PspWarnResultRptVO> queryAllCurrDownOrg(PspWarnResultRptVO pspWarnResultRptVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PspWarnResultRpt> pspWarnResultRpts = pspWarnResultRptDao.queryAllCurrDownOrgByPage(pspWarnResultRptVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pspWarnResultRpts.size());
		List<PspWarnResultRptVO> list = null;
		try {
			pageSet(pspWarnResultRpts, pspWarnResultRptVo);
			list = (List<PspWarnResultRptVO>) beansCopy(pspWarnResultRpts, PspWarnResultRptVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}
}
